{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.61390435,  0.16940091,  0.50286746,  0.72404753],\n",
       "       [ 0.74291141,  0.3233356 ,  0.77395247,  0.07985978],\n",
       "       [ 0.38582407,  0.94037643,  0.10466757,  0.82924723],\n",
       "       [ 0.30789176,  0.43289267,  0.8938481 ,  0.50500711]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 随机生成数组\n",
    "a = np.random.rand(4, 4)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0.61390435,  0.16940091,  0.50286746,  0.72404753],\n",
       "        [ 0.74291141,  0.3233356 ,  0.77395247,  0.07985978],\n",
       "        [ 0.38582407,  0.94037643,  0.10466757,  0.82924723],\n",
       "        [ 0.30789176,  0.43289267,  0.8938481 ,  0.50500711]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数组转化为矩阵\n",
    "randMat = np.mat(a)\n",
    "randMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0.78739972,  1.26882864,  0.13904985, -1.55789867],\n",
       "        [-1.39140733,  0.5247943 ,  1.03841716,  0.20679021],\n",
       "        [-0.30349088, -0.02309348, -0.57097904,  1.37635459],\n",
       "        [ 1.24982575, -1.18255648,  0.03570851,  0.31661786]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求逆\n",
    "inv = randMat.I\n",
    "inv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[  1.00000000e+00,  -2.22044605e-16,   0.00000000e+00,\n",
       "           5.55111512e-17],\n",
       "        [ -5.55111512e-17,   1.00000000e+00,   0.00000000e+00,\n",
       "           6.93889390e-17],\n",
       "        [ -5.55111512e-17,  -5.55111512e-17,   1.00000000e+00,\n",
       "          -5.55111512e-17],\n",
       "        [ -6.93889390e-18,  -5.55111512e-17,  -1.11022302e-16,\n",
       "           1.00000000e+00]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "randMat * inv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[  0.00000000e+00,  -2.22044605e-16,   0.00000000e+00,\n",
       "           5.55111512e-17],\n",
       "        [ -5.55111512e-17,  -2.22044605e-16,   0.00000000e+00,\n",
       "           6.93889390e-17],\n",
       "        [ -5.55111512e-17,  -5.55111512e-17,   0.00000000e+00,\n",
       "          -5.55111512e-17],\n",
       "        [ -6.93889390e-18,  -5.55111512e-17,  -1.11022302e-16,\n",
       "           0.00000000e+00]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myEye = randMat * inv\n",
    "myEye - np.eye(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
